package org.hxzon.configdesigner.web.pages;

import org.apache.tapestry5.EventConstants;
import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.OnEvent;
import org.hxzon.configdesigner.core.CfgValue;
import org.hxzon.configdesigner.web.pages.base.PageBase;
import org.hxzon.configdesigner.web.util.CfgUtil;

public class DelElement extends PageBase {

    @InjectPage
    private View pageView;

    @OnEvent(value = EventConstants.ACTIVATE)
    Object delete(int indexCode) {
        CfgValue child = CfgUtil.findCfg(indexCode);
        if (child == null) {
            return pageView.withInit(0);
        }
        child.getParent().removeValue(child);
        return pageView.withInit(child.getParent().indexCode());
    }
}
